import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../public_util.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    IntegralAddressState state, Dispatch dispatch, ViewService viewService) {
  return Scaffold(
    backgroundColor: Color.fromRGBO(248, 248, 248, 1),
    appBar: AppBar(
      title: Text(
        '收货地址管理',
        style: TextStyle(
            color: Color.fromRGBO(47, 47, 47, 1),
            fontSize: setSp(16),
            fontWeight: FontWeight.bold),
      ),
      leading: GestureDetector(
          onTap: () {
            Navigator.pop(viewService.context);
          },
          child: Icon(Icons.arrow_back_ios_rounded,
              color: Color.fromRGBO(47, 47, 47, 1))),
      actions: [
        GestureDetector(
            onTap: () {
              Navigator.pushNamed(viewService.context, 'task_address_edit',arguments:{'title':'新增收货地址'}).then((value) {
                print('接收到的返回数据$value');
              });
            },
            child: Container(
              padding: EdgeInsets.all(15.0),
              alignment: Alignment.center,
              child: Text(
                '新增',
                style: TextStyle(
                  color: Color.fromRGBO(255, 37, 38, 1),
                  fontSize: setSp(14),
                ),
              ),
            ))
      ],
      centerTitle: true,
      backgroundColor: Colors.white,
      elevation: 0.0,
      brightness: Brightness.light,
    ),
    body: ConstrainedBox(
        constraints: BoxConstraints.expand(),
        child: _emptyDataView(state, dispatch, viewService),
    ),
  );
}

Widget _emptyDataView(
    IntegralAddressState state, Dispatch dispatch, ViewService viewService) {
  return Container(
    color: Color.fromRGBO(248, 248, 248, 1),
    child: Column(
      children: [
        Container(
          width: ScreenUtil.screenWidth,
          alignment: Alignment.center,
          padding: EdgeInsets.only(top: setWidth(70), bottom: setWidth(20)),
          child: Image.asset(
            'assets/images/user_center/task_address.png',
            width: setWidth(260),
            fit: BoxFit.fitWidth,
          ),
        ),
        Container(
          width: ScreenUtil.screenWidth,
          alignment: Alignment.center,
          child: Text(
            '你暂未添加收货地址',
            style: TextStyle(
                color: Color.fromRGBO(136, 136, 136, 1),
                fontSize: setSp(15),
                fontWeight: FontWeight.bold),
          ),
        ),
        InkWell(
          onTap: () {
            Navigator.pushNamed(viewService.context, 'task_address_edit',arguments:{'title':'新增收货地址'}).then((value) {
              print('接收到的返回数据$value');
            });
          },
          child: Container(
            height: setWidth(40),
            margin: EdgeInsets.only(
                top: setWidth(50), left: setWidth(33), right: setWidth(33)),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Color.fromRGBO(255, 37, 38, 1),
              borderRadius: BorderRadius.circular(setWidth(40)),
            ),
            child: Text(
              '新增地址',
              style: TextStyle(
                fontSize: setSp(15),
                color: Colors.white,
              ),
            ),
          ),
        )
      ],
    ),
  );
}

Widget _existDataView(
    IntegralAddressState state, Dispatch dispatch, ViewService viewService) {
  return ListView.builder(
    padding: EdgeInsets.only(
      bottom: setWidth(10),
    ),
    itemCount: 2,
    itemBuilder: (BuildContext context, int index) {
      return Container(
        margin: EdgeInsets.only(
            left: setWidth(15), right: setWidth(15), top: setWidth(10)),
        padding: EdgeInsets.symmetric(
            horizontal: setWidth(12), vertical: setWidth(12)),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(setWidth(8)),
            color: Colors.white),
        child: Column(
          children: [
            Offstage(
              offstage: index == 0 ? false : true,
              child: Container(
                margin: EdgeInsets.only(bottom: setWidth(12)),
                child: Row(
                  children: [
                    Container(
                      padding: EdgeInsets.symmetric(
                          horizontal: setWidth(4), vertical: setWidth(2)),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(setWidth(2)),
                          color: Color.fromRGBO(255, 37, 38, 1)),
                      child: Text(
                        '默认',
                        style: TextStyle(
                          fontSize: setSp(10),
                          color: Colors.white,
                        ),
                      ),
                    ),
                    SizedBox(
                      width: setWidth(4),
                    ),
                    Container(
                      padding: EdgeInsets.symmetric(
                          horizontal: setWidth(4), vertical: setWidth(2)),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(setWidth(2)),
                          color: Color.fromRGBO(255, 104, 45, 1)),
                      child: Text(
                        '公司',
                        style: TextStyle(
                          fontSize: setSp(10),
                          color: Colors.white,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Row(
              children: [
                Expanded(
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Text(
                            "彭于晏",
                            style: TextStyle(
                              color: Color.fromRGBO(47, 47, 47, 1),
                              fontSize: setSp(14),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(3),
                          ),
                          Text(
                            "15737188888",
                            style: TextStyle(
                              color: Color.fromRGBO(153, 153, 153, 1),
                              fontSize: setSp(12),
                            ),
                          ),
                        ],
                      ),
                      SizedBox(
                        height: setWidth(7),
                      ),
                      Text(
                        "地址：河南省郑州市金水区郑州东站对面绿地之窗",
                        style: TextStyle(
                          color: Color.fromRGBO(68, 68, 68, 1),
                          fontSize: setSp(13),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: setWidth(15)),
                  color: Color.fromRGBO(238, 238, 238, 1),
                  width: setWidth(1),
                  height: setWidth(26),
                ),
                GestureDetector(
                  onTap: () {},
                  child: Container(
                    padding: EdgeInsets.only(left: setWidth(15)),
                    child: Text(
                      '编辑',
                      style: TextStyle(
                        fontSize: setSp(13),
                        color: Color.fromRGBO(255, 37, 38, 1),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      );
    },
  );
}
